import { _decorator, Component, Node } from 'cc';
import { GlobalData } from '../Data/GlobalData';
const { ccclass, property } = _decorator;

@ccclass('BunManger')
/**
 * 包子管理
 */
export class BunManger {

    private constructor() { }

    /** 单例实例 */
    public static readonly instance: BunManger = new BunManger();

    //包子数组
    public BunNumArray: number[] = [];

    //筷子数组
    public StickNumArray: number[] = [];

    //包子最多
    public BunMax: number = 4;

    /**
     * 创建包子
     */
    public CreateBunNum() {
        let bun_num: number = Math.floor(Math.random() * this.BunMax);
        this.BunNumArray.push(bun_num);
        if (GlobalData.CurrentLevel == 0) {
            this.StickNumArray.push(bun_num);
            this.StickNumArray.push(bun_num);
        }
    }

    /**
     * 返回豆包数
     */
    public ReturnBunNum(): number {
        let bun_ran: number = Math.floor(Math.random() * this.BunNumArray.length);
        let bun_num: number = this.BunNumArray[bun_ran];
        this.BunNumArray.splice(bun_ran, 1);
        return bun_num;
    }

    /**
     * 返回筷子
     */
    public ReturnStickNum(): number {

        if (this.StickNumArray.length == 0) {
            return Math.floor(Math.random() * this.BunMax);
        }

        let stick_ran: number = Math.floor(Math.random() * this.StickNumArray.length);
        let stick_num: number = this.StickNumArray[stick_ran];
        this.StickNumArray.splice(stick_ran, 1);
        return stick_num;
    }


}


